package com.xinqi.modules.sys.stats.manager.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.mybatis.data.service.impl.BaseServiceImpl;
import com.xinqi.modules.sys.stats.domain.SchoolTeachingDayStEntity;
import com.xinqi.modules.sys.stats.dto.req.SchoolTeachingDayStQueryDTO;
import com.xinqi.modules.sys.stats.dto.rsp.SchoolOverviewResultDTO;
import com.xinqi.modules.sys.stats.dto.rsp.SchoolTeachingCountResultDTO;
import com.xinqi.modules.sys.stats.dto.rsp.SchoolTeachingDayStResultDTO;
import com.xinqi.modules.sys.stats.manager.SchoolTeachingDayStManager;
import com.xinqi.modules.sys.stats.mapper.SchoolTeachingDayStMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * 学校教学数据统计管理层实现
 *
 * @author: wenjie
 * @date: 2023/08/24
 */
@Service
@RequiredArgsConstructor
public class SchoolTeachingDayStManagerImpl extends BaseServiceImpl<SchoolTeachingDayStMapper, SchoolTeachingDayStEntity> implements SchoolTeachingDayStManager {

    /**
     * 自定义分页查询
     */
    @Override
    public Page<SchoolTeachingDayStResultDTO> findPage(Page<Object> page, LocalDateTime startTime, LocalDateTime endTime) {
        return this.baseMapper.findPage(page, startTime, endTime);
    }

    /**
     * 自定义列表查询
     */
    @Override
    public List<SchoolTeachingDayStResultDTO> findList(SchoolTeachingDayStQueryDTO query) {
        return this.baseMapper.findList(query);
    }

    /**
     * 根据id查询 学校教学数据统计数据
     */
    @Override
    public SchoolTeachingDayStEntity findById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return getById(id);
    }

    /**
     * 根据id删除 学校教学数据统计数据
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return this.removeById(id);
    }

    @Override
    public List<SchoolTeachingDayStEntity> findAllSchools() {
        return this.baseMapper.findAllSchools();
    }

    @Override
    public List<SchoolTeachingCountResultDTO> findCountByRole(Integer userRole) {
        return this.baseMapper.findCountByRole(userRole);
    }

    @Override
    public List<SchoolTeachingCountResultDTO> findAddedCountByRoleAndDateRange(Integer userRole, LocalDateTime startTime, LocalDateTime endTime) {
        return this.baseMapper.findAddedCountByRoleAndDateRange(userRole, startTime, endTime);
    }

    @Override
    public List<SchoolTeachingCountResultDTO> findActivityCountByRoleAndDateRange(Integer userRole, LocalDateTime startTime, LocalDateTime endTime) {
        return this.baseMapper.findActivityCountByRoleAndDateRange(userRole, startTime, endTime);
    }

    @Override
    public List<SchoolTeachingCountResultDTO> findCourseContentCountByType(Integer type) {
        return this.baseMapper.findCourseContentCountByType(type);
    }

    @Override
    public List<SchoolTeachingCountResultDTO> findReleaseCourseContentByTypeAndDateRange(Integer type, LocalDateTime startTime, LocalDateTime endTime) {
        return this.baseMapper.findReleaseCourseContentByTypeAndDateRange(type, startTime, endTime);
    }

    @Override
    public List<SchoolTeachingCountResultDTO> findCourseClassCount() {
        return this.baseMapper.findCourseClassCount();
    }

    @Override
    public SchoolOverviewResultDTO overview() {
        return this.baseMapper.overview();
    }

    @Override
    public List<SchoolTeachingCountResultDTO> findContentSortListAndDateRange(LocalDateTime startTime, LocalDateTime endTime) {
        return this.baseMapper.findContentSortListAndDateRange(startTime, endTime);
    }

    @Override
    public List<SchoolTeachingCountResultDTO> findTodayAddedSchool() {
        return this.baseMapper.findTodayAddedSchool();
    }

}
